package com.example.xd.permissionlibrary.utils

import android.app.Activity
import android.app.role.RoleManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.provider.Settings
import android.telecom.TelecomManager
import android.widget.Toast

/**
 * @auther XuDan on 2020/7/16.
 */
fun toast(context: Context, s: String) {
    Toast.makeText(context, s, Toast.LENGTH_SHORT).show()
}

fun isFloatingPermission(context: Context): Boolean {
    var isHas = false
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (Settings.canDrawOverlays(context)) {
            isHas = true
        } else {
            isHas = false
        }
    } else {
        isHas = true
    }
    return isHas
}

fun isDefaultCall(context: Context): Boolean {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        val mTelecom: TelecomManager =
            context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager
        val packageName = context.packageName
        if (mTelecom.defaultDialerPackage.equals(packageName)) {
            return true
        } else {
            return false
        }
    }
    return false
}
